from datetime import datetime
from typing import Optional, List
from pydantic import BaseModel, Field, ConfigDict


class UserLevelBase(BaseModel):
    """
    用户等级基础模型
    包含用户等级的基本信息字段
    """
    level_name: str = Field(..., description="等级名称", max_length=50)
    required_points: int = Field(..., description="所需积分", ge=0)
    upgrade_points: int = Field(..., description="升级积分", ge=0)
    url: Optional[str] = Field(None, description="等级图标URL")
    url2: Optional[str] = Field(None, description="等级图标URL2")


class UserLevelCreate(UserLevelBase):
    """
    创建用户等级模型
    用于创建新等级时的数据验证
    """
    level_id: Optional[int] = Field(None, description="等级ID")


class UserLevelUpdate(BaseModel):
    """
    更新用户等级模型
    用于更新等级信息时的数据验证
    """
    level_name: Optional[str] = Field(None, description="等级名称", max_length=50)
    required_points: Optional[int] = Field(None, description="所需积分", ge=0)
    upgrade_points: Optional[int] = Field(None, description="升级积分", ge=0)
    url: Optional[str] = Field(None, description="等级图标URL")
    url2: Optional[str] = Field(None, description="等级图标URL2")


class UserLevelResponse(UserLevelBase):
    """
    用户等级响应模型
    用于返回等级信息
    """
    level_id: int = Field(..., description="等级ID")

    model_config = ConfigDict(from_attributes=True)


class UserLevelListResponse(BaseModel):
    """
    用户等级列表响应模型
    """
    total: int = Field(..., description="总数量")
    items: List[UserLevelResponse] = Field(..., description="等级列表")


class AwardPointsBase(BaseModel):
    """
    奖项积分基础模型
    包含奖项积分的基本信息字段
    """
    award_name: str = Field(..., description="奖项名称", max_length=50)
    points: int = Field(..., description="积分值", ge=0)


class AwardPointsCreate(AwardPointsBase):
    """
    创建奖项积分模型
    用于创建新奖项时的数据验证
    """
    pass


class AwardPointsUpdate(BaseModel):
    """
    更新奖项积分模型
    用于更新奖项信息时的数据验证
    """
    award_name: Optional[str] = Field(None, description="奖项名称", max_length=50)
    points: Optional[int] = Field(None, description="积分值", ge=0)


class AwardPointsResponse(AwardPointsBase):
    """
    奖项积分响应模型
    用于返回奖项信息
    """
    id: int = Field(..., description="奖项ID")

    model_config = ConfigDict(from_attributes=True)


class AwardPointsListResponse(BaseModel):
    """
    奖项积分列表响应模型
    """
    total: int = Field(..., description="总数量")
    items: List[AwardPointsResponse] = Field(..., description="奖项列表")


class LevelQuery(BaseModel):
    """
    等级查询模型
    """
    page: int = Field(1, description="页码", ge=1)
    size: int = Field(10, description="每页数量", ge=1, le=100)
    keyword: Optional[str] = Field(None, description="搜索关键词")


class AwardQuery(BaseModel):
    """
    奖项查询模型
    """
    page: int = Field(1, description="页码", ge=1)
    size: int = Field(10, description="每页数量", ge=1, le=100)
    keyword: Optional[str] = Field(None, description="搜索关键词")